package edu.gatech.cs2340.group7.wheresmystuffapp.views;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import edu.gatech.cs2340.group7.wheresmystuffapp.R;
import edu.gatech.cs2340.group7.wheresmystuffapp.presenters.UnlockAccountPresenter;

/**
 * View for unlocking an account
 * 
 * @author tbowling3
 * 
 */
public class UnlockAccountView extends Activity implements View.OnClickListener {
	private String PACKAGE_NAME;
	private UnlockAccountPresenter myPresenter;
	private EditText etAdminEmailUnlock;
	private Button bAdminUnlock;
	private TextView tvAdminUnlockResult;
	private Button bAdminCancelFromUnlock;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_unlock_account);
		initialize();
		myPresenter = new UnlockAccountPresenter(this);
		PACKAGE_NAME = getApplicationContext().getPackageName();
	}

	@Override
	public void onClick(View view) {
		String username = etAdminEmailUnlock.getText().toString();
		switch (view.getId()) {
		case R.id.b_admin_unlock:
			myPresenter.unlockAccount(username);
			break;
		case R.id.b_admin_cancel_from_unlock:
			Intent intent = new Intent(this, AdminMainMenuView.class);
			intent.setPackage(PACKAGE_NAME);
			startActivity(intent);
			break;
		}

	}

	/**
	 * Sets the result text view of the UnlockAccount activity to the given
	 * string
	 * 
	 * @param result
	 *            String to be set for the text view
	 */
	public void setResultText(String result) {
		tvAdminUnlockResult.setText(result);
		tvAdminUnlockResult.setTextColor(Color.RED);
	}

	/**
	 * Finds and sets each of the buttons and text edits and text views used by
	 * unlocking an account
	 */
	private void initialize() {
		etAdminEmailUnlock = (EditText) findViewById(R.id.et_admin_email_unlock);
		bAdminUnlock = (Button) findViewById(R.id.b_admin_unlock);
		bAdminCancelFromUnlock = (Button) findViewById(R.id.b_admin_cancel_from_unlock);
		tvAdminUnlockResult = (TextView) findViewById(R.id.tv_admin_unlock_result);

		etAdminEmailUnlock.setOnClickListener(this);
		bAdminUnlock.setOnClickListener(this);
		tvAdminUnlockResult.setOnClickListener(this);
		bAdminCancelFromUnlock.setOnClickListener(this);
	}
}
